package com.tajiang.business.setting.dialog;

import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.tajiang.business.R;
import com.tajiang.business.common.utils.SharedPreferencesUtils;
import com.tajiang.business.common.utils.ToastUtils;
import com.tajiang.business.common.widget.WheelView;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Administrator on 2016/8/22.
 */
public class ChoosePrintNumberDialog extends Dialog {

    @BindView(R.id.btn_ensure)
    TextView btnEnsure;
    @BindView(R.id.wv_print_num)
    WheelView wvPrintNum;

    onPrintAmountConfirmListener listener;

    public void setPrintAmountConfirmListener(onPrintAmountConfirmListener listener) {
        this.listener = listener;
    }

    public interface onPrintAmountConfirmListener{
        public void onPrintAmountConfirm(String printAmount);
    }

    public ChoosePrintNumberDialog(Context context) {
        super(context, R.style.dialog_operate);
        View view = LayoutInflater.from(context).inflate(R.layout.dialog_choose_print_number, null);
        setContentView(view);
        ButterKnife.bind(this);
        this.setCancelable(false);
        initView();
    }

    private void initView() {
        int position = 0;
        try{
            String strPosition = (String) SharedPreferencesUtils.get(SharedPreferencesUtils.PRINT_AMOUNT, "1");
            position = Integer.valueOf(strPosition) - 1;
        } catch (NumberFormatException e) {
            e.printStackTrace();
        }

        List<String> list = new ArrayList<String>();
        list.add("1");
        list.add("2");
        list.add("3");
        wvPrintNum.setOffset(1);
        wvPrintNum.setItems(list);
        wvPrintNum.setSeletion(position);
    }

    /**
     *
     */
    @OnClick(R.id.btn_ensure)
    public void onClick() {
        if (listener != null) {
            listener.onPrintAmountConfirm(wvPrintNum.getSeletedItem());
        }
        SharedPreferencesUtils.put(SharedPreferencesUtils.PRINT_AMOUNT, wvPrintNum.getSeletedItem());
        this.dismiss();
    }

}
